//
//  ReadDetailCollectionViewCell.m
//  A_Project_DLS151129_SQ
//
//  Created by 151129-49宋强 on 16/1/20.
//  Copyright © 2016年 www.lanou3g.com蓝鸥. All rights reserved.
//

#import "ReadDetailCollectionViewCell.h"


@interface ReadDetailCollectionViewCell ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;

@end

@implementation ReadDetailCollectionViewCell

- (void)dealloc
{
    [_dataArr release];
    [_tableView release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tableView = [[UITableView alloc] init];
        // _tableView.backgroundColor = [UIColor redColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.contentView addSubview:_tableView];
        [_tableView registerClass:[ReadDetailTableViewCell class] forCellReuseIdentifier:@"cell"];
        [_tableView release];
        //下拉刷新数据
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        //[header setTitle:@"下拉刷新" forState:MJRefreshStatePulling];
        //数据处理
        //代理人调用协议方法
        [self.reDelegate refresh];
        [_tableView reloadData];
        [self.tableView.mj_header endRefreshing];

     }];//上拉加载
        self.tableView.mj_header = header;
        MJRefreshAutoFooter *footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
            [self.loDelegate loading];
            [self.tableView reloadData];
            [self.tableView.mj_footer endRefreshing];
        }];
        self.tableView.mj_footer = footer;
    
        
      }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    _tableView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height );
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ReadDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    Model *m = _dataArr[indexPath.row];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:m.coverimg]];
    cell.contentLabel.text = m.content;
    cell.titleLabel.text = m.title;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 140;
}
//重写set方法
- (void)setDataArr:(NSArray *)dataArr
{
    if (_dataArr) {
        [_dataArr release];
    }
    _dataArr = [dataArr retain];
    [_tableView reloadData];
  }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Model *m = _dataArr[indexPath.row];
    
    
    [self.delegate jump:m.id Model:m];
}

@end
